package com.assignwork.service.impl;

import com.assignwork.dto.VoyageCabinNodeSearchDTO;
import com.assignwork.dto.VoyageCabinNodeSubmitDTO;
import com.assignwork.entity.VoyageCabinNode;
import com.assignwork.mapper.VoyageCabinNodeMapper;
import com.assignwork.service.ICommonService;
import com.assignwork.service.IVoyageCabinNodeService;
import com.assignwork.vo.VoyageCabinNodePageVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zaxxer.hikari.util.ConcurrentBag;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.cache.DictBizCache;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 分舱停时实现类
 */
@Service
@AllArgsConstructor
public class VoyageCabinNodeServiceImpl extends BaseServiceImpl<VoyageCabinNodeMapper, VoyageCabinNode> implements IVoyageCabinNodeService {

    private ICommonService commonService;

    @Override
    public IPage<VoyageCabinNodePageVO> selectVoyageCabinNodePage(VoyageCabinNodeSearchDTO dto, IPage<VoyageCabinNodePageVO> page) {
        List<VoyageCabinNodePageVO> data = baseMapper.selectVoyageCabinNodeList(dto, page);
        for (VoyageCabinNodePageVO vo : data) {
            if (!Func.isNull(vo.getUpdateUser())) {
                vo.setUpdateUserName(commonService.userName(vo.getUpdateUser().toString()));
            }
            if (!Func.isNull(vo.getCreateUser())) {
                vo.setCreateUserName(commonService.userName(vo.getCreateUser().toString()));
            }
            if (!Func.isNull(vo.getLoadType())) {
                vo.setLoadTypeName(DictBizCache.getValue("load_type", vo.getLoadType()));
            }
            if (!Func.isNull(vo.getHold())) {
                vo.setHoldName(DictBizCache.getValue("hold", vo.getHold()));
            }
        }
        return page.setRecords(data);
    }

    @Override
    public Boolean submitVoyageCabinNode(VoyageCabinNodeSubmitDTO dto) {
        VoyageCabinNode entity = BeanUtil.copy(dto, VoyageCabinNode.class);
        return super.saveOrUpdate(entity);
    }
}